<?php
// +----------------------------------------------------------------------
// | 云南喵云科技
// +----------------------------------------------------------------------
// | 官方网站: https://www.ymeoo.com
// +----------------------------------------------------------------------
// | Author: 喵大大 <mmteen@sina.com>
// +----------------------------------------------------------------------

/**
 * Created by 喵云科技
 * 官方网站: https://www.ymeoo.com
 * Email: miaoyunkj@sina.com
 * 作者：喵大大
 * Date:2021/9/26/026
 * Time:18:37
 */

namespace App\HttpController\Api;

use App\Model\UserModel;


class User extends Base
{

    public function login(){

        $params = $this->getRaw();
        $user = UserModel::create()->where(['username' => $params["username"],"password" => $params["password"]])->get();
        if($user){
            $token = $this->buildToken($user);
            $user["token"] = $token;
            $this->message(200,"登录成功",$user);
        }

        $this->message(400,"用户名或密码错误");
    }

    //登录用户菜单列表
    public function userRuleList()
    {
        $uid = $this->getUid();
        $groupId = A::create()->where(["id" => $uid])->scalar("group_id");

        $ruleIds = UserGroupRule::create()->where(["group_id" => $groupId])->column("rule_id");

        $userRule = UserRule::create()->where("id",$ruleIds,"in")->where("is_menu",1,"=")->all();

        $functions = new Functions();
        $treeRule = $functions->makeTree($userRule);

        $this->message(200,"ok",$treeRule);
    }

}